package cn.wolfcode.crm5.controller;

import cn.wolfcode.crm5.domain.User;
import cn.wolfcode.crm5.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @Autowired
    private IUserService userService;

    @RequestMapping("/userLogin")
    public String userLogin(String name,String password, HttpSession session){
        User user = userService.login(name,password);

        if (user == null){
            return "redirect:/login.html";
        }
        session.setAttribute("USER_IN_SESSION",user);
        return "redirect:/employee/list";
    }

    @RequestMapping("/nopermission")
    public String nopermission(){
        return "redirect:/nopermission.html";
    }
}
